<?php
class Http {

	/**
	 * Redirect browser
	 *
	 * Redirects browser to the specified URL and terminates the current script.
	 *
	 * @acces public
	 *
	 * @param string $sUrl URL of page which the browser should be directed to.
	 */
	function redirect_user($sUrl) {
		//header('Location: '.$sUrl);
		redirect($sUrl);
		exit;
	}

	/**
	 * Get URL of current page
	 *
	 * Returns URL of the current page without parameters
	 *
	 * @access public
	 *
	 * @return string URL of the current page
	 */
	function getCurrentPageUrl() {
		return URL_ROOT.'/'.basename($_SERVER['SCRIPT_NAME']);
	}

	/**
	 * Add parameter to URL
	 *
	 * Adds the specified parameter to an URL.
	 *
	 * @access public
	 *
	 * @param string $sUrl URL which a parameter should be added to.
	 * @param string $sName Name of a parameter
	 * @param string $sValue Value of a parameter
	 * @param boolean $bReplace Means to replace parameter if it already exists in URL
	 * @return string Modified URL
	 */
	function addUrlParameter($sUrl, $sName, $sValue, $bReplace = true) {
		if (preg_match('/\?/', $sUrl) == 0) {
			$sUrl = $sUrl.'?';
		}
		else {
			if ($bReplace) {
				$sUrl = preg_replace('/'.$sName.'=[^&]*&?/', '', $sUrl);
			}
			$sUrl = preg_replace('/[^?&]$/', '$0&', $sUrl);
		}
		$sUrl .= urlencode($sName).'='.urlencode($sValue);
		return $sUrl;
	}

	/**
	 * Remove parameter from URL
	 *
	 * Removes the specified parameter from an URL.
	 *
	 * @access public
	 *
	 * @param string $sUrl URL which a parameter should be added to.
	 * @param string $sName Name of a parameter
	 * @return string Modified URL
	 */
	function removeUrlParameter($sUrl, $sName) {
		$sUrl = preg_replace('/'.$sName.'=[^&]*&?/', '', $sUrl);
		$sUrl = preg_replace('/&$/', '', $sUrl);
		return $sUrl;
	}

}

?>